package com.mall.hadoop.job.abilityrds;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.log4j.Logger;

import com.mall.manager.service.AbilityRdsService;
import com.mall.manager.service.AreaMapService;

public class AbilityRdsReduce extends Reducer<Text, IntWritable, Text, IntWritable>{

	Logger logger = Logger.getLogger(AbilityRdsReduce.class);
			
	@Override
	protected void reduce(Text key, Iterable<IntWritable> iter,Context context)throws IOException, InterruptedException {
	
		try{
			Map<String,Object> map = new HashMap<String,Object>();
			String[] k = key.toString().split("s");
			if(k[1].contains("f")){
				map = AreaMapService.loadAreaMap("p");
			}else if(k[1].contains("h")){
				map = AreaMapService.loadAreaMap("c");
			}else{
				map = AreaMapService.loadAreaMap("a");
			}
			for(IntWritable iw:iter){
				AbilityRdsService.insertBatch(k[0],k[1], iw.get(), map);
			}
		}catch(Exception e){
			logger.info("AbilityRdsReduce存储八大能力异常："+e.toString());
		}
	}

}
